package com.acme.domain.bank;

import com.acme.domain.client.Client;
import com.acme.exceptions.*;

public class Bank {
	

	private int numberOfClients = 0;
	private final Client[] clients = new Client [10];

	public Bank() {
	}

	public void addClient(Client client)
			throws ClientAlreadyExistsException, ClientCountLimitException  {
		if (numberOfClients>10){
			throw new ClientCountLimitException("Error adding client: " +
					"clients>10");
		} else {
			for(Client cl : clients) {
				if ( client.equals(cl) ){
					throw new ClientAlreadyExistsException();
				}
			}
			clients[numberOfClients++] = client;
		}
	}

	public int getNumberOfClients() {
		return numberOfClients;
	}
	
	public Client getClient(int i) throws ClientCountLimitException{
		if (i>10) {
			throw new ClientCountLimitException("Error geting clients! " +
					"(too many)");
		} else if (i<=0) {
			throw new ClientCountLimitException("Error geting clients! " +
					"(wrong value or no clients in the bank)");
		} else {
			return clients[i-1];
		}
	}
	
	public void printClients() {
		for (int i = 0;i<numberOfClients;i++){
			System.out.println(clients[i].toString());
		}
	}
}
